package com.xian.im.modules.command.group.handler;

import com.xian.im.common.constant.CommandCodeConstant;
import com.xian.im.common.model.dto.GroupDto;
import com.xian.im.common.model.dto.GroupUserDto;
import com.xian.im.common.proto.MsgRequest;
import com.xian.im.common.proto.MsgResponse;
import com.xian.im.common.utils.bussiness.XimResponseUtil;
import com.xian.im.common.utils.sys.SpringContextHolder;
import com.xian.im.modules.command.group.AbsGroupCommand;
import com.xian.im.modules.im.core.IGroupUserCoreService;
import com.xian.im.modules.message.GroupHandler;

/**
 * @program: xian-im-server
 * @description:  群成员接触禁言
 * @author: liru.xian
 * @create: 2021-01-28 22:48
 **/
public class GroupOpenMemberMute extends AbsGroupCommand {

    @Override
    public void handler(MsgRequest request, String ctx, GroupDto groupEntity) {
        GroupUserDto groupUserDto = new GroupUserDto();
        groupUserDto.setGroupUniqueId(groupEntity.getGroupUniqueId());
        groupUserDto.setUserAccount(request.getToAccount());
        SpringContextHolder.getBean(IGroupUserCoreService.class).unmute(groupUserDto);
        MsgResponse response = XimResponseUtil.buildSuccess(userChannelClient().session(ctx));
        response.setBody(getSession(ctx).getNickname()+" 解除禁言");
        response.setGroupUniqueId(groupEntity.getGroupUniqueId());
        GroupHandler.groupSendAll(response,groupEntity.getGroupUniqueId());
    }

    /**
     * 群组code
     *
     * @return
     */
    @Override
    public String cmdCode() {
        return CommandCodeConstant.GROUP_OPEN_MEMBER_MUTE;
    }
}
